package CommonClasses.StringClass;

import org.testng.annotations.Test;

public class StringDemo {
    @Test
    public void test1() {
        // "abc"字符串常量，也是一个对象
        String str1 = "abc";
        String str2 = new String("abc");
        String str3 = "abc";
        //==比较的是引用指向的地址值
        System.out.println(str1 == str2);//false
        System.out.println(str1 == str3);//true
        System.out.println(str2 == str3);//false
        //equals比较的是内容
        System.out.println(str1.equals(str2));//true
        System.out.println(str1.equals(str3));//true
        System.out.println(str2.equals(str3));//true
    }
    @Test
    public void test2() {
        String str = "java AndroidA";
        System.out.println(str.length());//13
        char[] chars = str.toCharArray();
        char ch = str.charAt(5);//A
        System.out.println(ch);
        System.out.println(str.indexOf('A'));//5
        System.out.println(str.indexOf('X'));//-1
        System.out.println(str.indexOf('A', 6));//12
        System.out.println(str.indexOf("And"));//5
        System.out.println(str.lastIndexOf('A'));//12
    }

    @Test
    public void test3() {
        String str1 = "java";
        String str2 = "Java";
        System.out.println(str1.equals(str2));//false
        System.out.println(str1.equalsIgnoreCase(str2));//true

        String str = "java AndroidA";
        System.out.println(str.contains("And"));//true
        System.out.println(str.startsWith("java"));//true
        //offset:偏移
        System.out.println(str.startsWith("And", 5));//true
        System.out.println(str.endsWith("oidA"));//true
        System.out.println(str.isEmpty());//false
        // ""空字符串，也是一个对象
        System.out.println("".isEmpty());//true

    }
    @Test
    public void test4(){


        String s1 = "coder";
        String s2 = "coder";
        String s3 = "coder" + s2;
        String s4 = "coder" + "coder";
        String s5 = s1 + s2;
        System.out.println(s3 == s4);
        System.out.println(s3 == s5);
        System.out.println(s4 == "codercoder");
    }
    @Test
    public void test5(){
        String s1=new String("nowcoder");
        String s2=new String("nowcoder");
        System.out.println(s1==s2);
        System.out.println(s1=="nowcoder");
        System.out.println(s2=="nowcoder");
    }
    @Test
    public void test44() {
        System.out.println(Integer.MAX_VALUE);

        Integer integer = 4;
        int i = integer.intValue();

        int num = 5;
        num = num + 3;

        integer = integer + 3;
        System.out.println(integer);//7
    }

    @Test
    public void test55() {
        String str1 = 12 + "";
        String str2 = Integer.toString(13); // "13"

        int i = Integer.parseInt("23"); // 23

        Integer integer = new Integer("24");
        int i1 = integer.intValue();

        double d = Double.parseDouble("3.14");
        boolean b = Boolean.parseBoolean("true");

    }
    @Test
    public void test6(){
        StringBuilder ab=new StringBuilder("12345");
        StringBuffer sb=new StringBuffer("12345");
        System.out.println(sb.charAt(2));
        System.out.println(ab.charAt(3));
    }
}
